package com.liyang.springcloud.controller;

import com.liyang.springcloud.common.entities.CommonResult;
import com.liyang.springcloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @BelongsProject: cloud-2024
 * @BelongsPackage: com.liyang.springcloud.controller
 * @Author: liyang
 * @CreateTime: 2024-01-10  11:22
 * @Description: 账户服务
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/account")
public class AccountController {

    @Resource
    private AccountService accountService;

    /**
     * @description: 扣减账户余额
     * @author: liyang
     * @date: 2024/1/10 11:24
     * @param: userId 用户
     * @param: money 金额
     * @return: com.liyang.springcloud.common.entities.CommonResult
     **/
    @RequestMapping("/decrease")
    public CommonResult decrease(@RequestParam("userId") Long userId, @RequestParam("money") BigDecimal money) {
        accountService.decrease(userId, money);
        return new CommonResult(200, "扣减账户余额成功！");
    }
}
